#ifndef QSCRIPTENGINETHREAD_H
#define QSCRIPTENGINETHREAD_H

#include <QThread>
#include <QMutex>
#include <QtScript>
#include <QVariant>
//#include <QScopedPointer>
#include <QtCore/QTimer>

#include "AIThread.h"
#include "cvmat.h"


class AIScriptEngine : public QObject
{
    Q_OBJECT

    // QEngine prototypes
    //QCLImageFormatPrototype m_QCLImageFormatPrototype;
    //Vec4fPrototype          m_Vec4fPrototype;
    //Vec4bPrototype          m_Vec4bPrototype;
    //Vec3bPrototype          m_Vec3bPrototype;

public:
    AIScriptEngine(QObject *parent = 0);
    ~AIScriptEngine();

    QMutex mutex;
    QScriptEngine engine;
    QScriptValue evaluate(const QScriptProgram & program);

public slots:
    void onTimeOut();
    void onSuspend();
    void onResume(int mSec = 0);
    void executeProgram(QScriptProgram program, QVariant var = QVariant());
    void executeProgramString(QString strProgram, QVariant var = QVariant());
    void setLoopProgram(QScriptProgram program);
    void setLoopProgramString(QString strProgram);
    void newGlobalQObject(QObject * pObject, QString name);

signals:
    void update(QScriptEngine *);

private:
    QTimer m_Timer;
    QScriptProgram m_loopProgram;

    Q_DISABLE_COPY(AIScriptEngine)
};



#endif // QSCRIPTENGINETHREAD_H
